﻿

using Controller.i18n.entity;
using HBase;
using hCommand;
using hconnect;
using MongoDB.Bson.IO;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Controller {
    public abstract class AbsCraneJjlAllocate:SingleTaskAllocateJobTask<TaskCrane> {

        protected IWCSServer taskServer = WMSDalFactray.getDal<IWCSServer>();
        public AbsCraneJjlAllocate() {
            time = 200;
        } 
        protected override long oneMaxTime() {
            return 12000;//每次成功sleep10秒
        } 
        public override SocketZtTaskConnect getTaskConnect(BaseTask taskModel) {
            return (CraneConnect)TaskPool.get<CraneConnect>(getCNo());
        } 
        public override Type getSynchro() {
            return TaskPool.get<CraneSynchro>(getCNo()).GetType();
        } 
        public override bool chechModeDB() {
            BParam p = MyCache.getValue<BParam>(getCNo());
            if (p == null) {
                console(InfoC.consol_Crane_overStop,"垛机配置异常" + getCNo());
                return false;
            }
            //验证垛机mechine_status 表中overstop 位1 代表循环停止

            if (p.v == 1) {
                console(InfoC.consol_Crane_overStop,"垛机循环停止");
                return false;
            }
            return true;
        }
        sealed  public override BaseTask analyseSingleTaskModel(AbsStatus gcs) {
            List<TaskCrane> tclist = getCanWorkNewTask<TaskCrane>(); 
            CraneStatus craneStatus = (CraneStatus)gcs; 
            foreach (TaskCrane crane in tclist) {
                if (crane.status != (int)CoreTaskParamStatus.待执行 && crane.status != (int)CoreTaskParamStatus.删除) {
                    consoleOnly(InfoC.consoleOnly_crane_Working,"数据库有未完成任务" + crane.taskNo);
                    return null;
                }
            } 
            return analyseSingleTaskModel(craneStatus,tclist); 
        } 
        public abstract BaseTask analyseSingleTaskModel(CraneStatus gcs,List<TaskCrane> tclist);

    }
}
